package page

import (
	"encoding/json"
	"net/http"
	"net/netip"
	"time"
)

func Ping(w http.ResponseWriter, r *http.Request) {
	var data = make(map[string]any)
	data["Host"] = r.Host
	data["Header"] = r.Header
	data["Method"] = r.Method
	data["URL"] = r.URL
	ip, _ := netip.ParseAddrPort(r.RemoteAddr)
	data["IP"] = ip.Addr()
	data["Port"] = ip.Port()
	_ = r.ParseForm()
	data["Form"] = r.Form
	data["PostForm"] = r.PostForm
	data["URI"] = r.RequestURI
	now := time.Now()
	data["Time"] = now.Format("2006/01/02 15:04:05 -0700")
	data["TimeStamp"] = now.UnixMilli()
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	marshal, _ := json.Marshal(&data)
	w.Write(marshal)
}
